From c3841e701988474911da4636c367a2eb2d062a10 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Sat, 11 Oct 2003 13:32:16 +0000 Subject: [PATCH] Fixes based on comments from Marco Pesenti Gritti. Sat Oct 11 15:23:27 2003 Kristian Rietveld Fixes based on comments from Marco Pesenti Gritti. * gtk/gtkentry.c (gtk_entry_set_text): block the completion changed signal handler, avoids the completion popup to popup when text is set programmatically in most cases (we actually have to handle this in the _editable functions as well, but that will break popping up when the user actually typed something :), (gtk_entry_completion_key_press): when handling enter, bail out when nothing has been selected, (gtk_entry_completion_changed): don't popdown when the entry content changed. * gtk/gtkentrycompletion.c (gtk_entry_completion_init), (gtk_entry_completion_selected_changed): unselect_all on the first selected changed signal. Avoids having a default row selected, (_gtk_entry_completion_popup): don't select the first row by default. * gtk/gtkentryprivate.h (struct _GtkEntryCompletionPrivate): add a first_sel_changed field. --- ChangeLog | 22 ++++++++++++++++++++++ ChangeLog.pre-2-10 | 22 ++++++++++++++++++++++ ChangeLog.pre-2-4 | 22 ++++++++++++++++++++++ ChangeLog.pre-2-6 | 22 ++++++++++++++++++++++ ChangeLog.pre-2-8 | 22 ++++++++++++++++++++++ gtk/gtkentry.c | 15 ++++++++++----- gtk/gtkentrycompletion.c | 30 +++++++++++++++++++++++------- gtk/gtkentryprivate.h | 1 + 8 files changed, 144 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4ed0b0bc3..edbe2882d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +Sat Oct 11 15:23:27 2003 Kristian Rietveld + + Fixes based on comments from Marco Pesenti Gritti. + + * gtk/gtkentry.c (gtk_entry_set_text): block the completion changed + signal handler, avoids the completion popup to popup when text is + set programmatically in most cases (we actually have to handle this + in the _editable functions as well, but that will break popping up + when the user actually typed something :), + (gtk_entry_completion_key_press): when handling enter, bail out + when nothing has been selected, + (gtk_entry_completion_changed): don't popdown when the entry content + changed. + + * gtk/gtkentrycompletion.c (gtk_entry_completion_init), + (gtk_entry_completion_selected_changed): unselect_all on the + first selected changed signal. Avoids having a default row selected, + (_gtk_entry_completion_popup): don't select the first row by default. + + * gtk/gtkentryprivate.h (struct _GtkEntryCompletionPrivate): add a + first_sel_changed field. + Fri Oct 10 23:02:58 2003 Matthias Clasen * demos/gtk-demo/menus.c: Replace GtkItemFactory by GtkUIManager diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index e4ed0b0bc3..edbe2882d2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,25 @@ +Sat Oct 11 15:23:27 2003 Kristian Rietveld + + Fixes based on comments from Marco Pesenti Gritti. + + * gtk/gtkentry.c (gtk_entry_set_text): block the completion changed + signal handler, avoids the completion popup to popup when text is + set programmatically in most cases (we actually have to handle this + in the _editable functions as well, but that will break popping up + when the user actually typed something :), + (gtk_entry_completion_key_press): when handling enter, bail out + when nothing has been selected, + (gtk_entry_completion_changed): don't popdown when the entry content + changed. + + * gtk/gtkentrycompletion.c (gtk_entry_completion_init), + (gtk_entry_completion_selected_changed): unselect_all on the + first selected changed signal. Avoids having a default row selected, + (_gtk_entry_completion_popup): don't select the first row by default. + + * gtk/gtkentryprivate.h (struct _GtkEntryCompletionPrivate): add a + first_sel_changed field. + Fri Oct 10 23:02:58 2003 Matthias Clasen * demos/gtk-demo/menus.c: Replace GtkItemFactory by GtkUIManager diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index e4ed0b0bc3..edbe2882d2 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,25 @@ +Sat Oct 11 15:23:27 2003 Kristian Rietveld + + Fixes based on comments from Marco Pesenti Gritti. + + * gtk/gtkentry.c (gtk_entry_set_text): block the completion changed + signal handler, avoids the completion popup to popup when text is + set programmatically in most cases (we actually have to handle this + in the _editable functions as well, but that will break popping up + when the user actually typed something :), + (gtk_entry_completion_key_press): when handling enter, bail out + when nothing has been selected, + (gtk_entry_completion_changed): don't popdown when the entry content + changed. + + * gtk/gtkentrycompletion.c (gtk_entry_completion_init), + (gtk_entry_completion_selected_changed): unselect_all on the + first selected changed signal. Avoids having a default row selected, + (_gtk_entry_completion_popup): don't select the first row by default. + + * gtk/gtkentryprivate.h (struct _GtkEntryCompletionPrivate): add a + first_sel_changed field. + Fri Oct 10 23:02:58 2003 Matthias Clasen * demos/gtk-demo/menus.c: Replace GtkItemFactory by GtkUIManager diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index e4ed0b0bc3..edbe2882d2 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,25 @@ +Sat Oct 11 15:23:27 2003 Kristian Rietveld + + Fixes based on comments from Marco Pesenti Gritti. + + * gtk/gtkentry.c (gtk_entry_set_text): block the completion changed + signal handler, avoids the completion popup to popup when text is + set programmatically in most cases (we actually have to handle this + in the _editable functions as well, but that will break popping up + when the user actually typed something :), + (gtk_entry_completion_key_press): when handling enter, bail out + when nothing has been selected, + (gtk_entry_completion_changed): don't popdown when the entry content + changed. + + * gtk/gtkentrycompletion.c (gtk_entry_completion_init), + (gtk_entry_completion_selected_changed): unselect_all on the + first selected changed signal. Avoids having a default row selected, + (_gtk_entry_completion_popup): don't select the first row by default. + + * gtk/gtkentryprivate.h (struct _GtkEntryCompletionPrivate): add a + first_sel_changed field. + Fri Oct 10 23:02:58 2003 Matthias Clasen * demos/gtk-demo/menus.c: Replace GtkItemFactory by GtkUIManager diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index e4ed0b0bc3..edbe2882d2 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,25 @@ +Sat Oct 11 15:23:27 2003 Kristian Rietveld + + Fixes based on comments from Marco Pesenti Gritti. + + * gtk/gtkentry.c (gtk_entry_set_text): block the completion changed + signal handler, avoids the completion popup to popup when text is + set programmatically in most cases (we actually have to handle this + in the _editable functions as well, but that will break popping up + when the user actually typed something :), + (gtk_entry_completion_key_press): when handling enter, bail out + when nothing has been selected, + (gtk_entry_completion_changed): don't popdown when the entry content + changed. + + * gtk/gtkentrycompletion.c (gtk_entry_completion_init), + (gtk_entry_completion_selected_changed): unselect_all on the + first selected changed signal. Avoids having a default row selected, + (_gtk_entry_completion_popup): don't select the first row by default. + + * gtk/gtkentryprivate.h (struct _GtkEntryCompletionPrivate): add a + first_sel_changed field. + Fri Oct 10 23:02:58 2003 Matthias Clasen * demos/gtk-demo/menus.c: Replace GtkItemFactory by GtkUIManager diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 28ecae518f..268d35dc33 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -3447,10 +3447,14 @@ gtk_entry_set_text (GtkEntry *entry, const gchar *text) { gint tmp_pos; + GtkEntryCompletion *completion; g_return_if_fail (GTK_IS_ENTRY (entry)); g_return_if_fail (text != NULL); + completion = gtk_entry_get_completion (entry); + g_signal_handler_block (entry, completion->priv->changed_id); + /* Actually setting the text will affect the cursor and selection; * if the contents don't actually change, this will look odd to the user. */ @@ -3461,6 +3465,8 @@ gtk_entry_set_text (GtkEntry *entry, tmp_pos = 0; gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &tmp_pos); + + g_signal_handler_unblock (entry, completion->priv->changed_id); } void @@ -4476,7 +4482,8 @@ gtk_entry_completion_timeout (gpointer data) completion->priv->completion_timeout = 0; - if (strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry))) >= completion->priv->minimum_key_length) + if (strlen (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry))) + >= completion->priv->minimum_key_length) { gint matches; gint actions; @@ -4573,7 +4580,8 @@ gtk_entry_completion_key_press (GtkWidget *widget, gboolean entry_set; sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (completion->priv->tree_view)); - gtk_tree_selection_get_selected (sel, &model, &iter); + if (!gtk_tree_selection_get_selected (sel, &model, &iter)) + return FALSE; g_signal_emit_by_name (completion, "match_selected", model, &iter, &entry_set); @@ -4619,9 +4627,6 @@ gtk_entry_completion_changed (GtkWidget *entry, { GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data); - if (GTK_WIDGET_MAPPED (completion->priv->popup_window)) - _gtk_entry_completion_popdown (completion); - /* (re)install completion timeout */ if (completion->priv->completion_timeout) g_source_remove (completion->priv->completion_timeout); diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c index 42813bf671..df26ce8a50 100644 --- a/gtk/gtkentrycompletion.c +++ b/gtk/gtkentrycompletion.c @@ -100,6 +100,8 @@ static gboolean gtk_entry_completion_list_button_press (GtkWidget static gboolean gtk_entry_completion_action_button_press (GtkWidget *widget, GdkEventButton *event, gpointer user_data); +static void gtk_entry_completion_selection_changed (GtkTreeSelection *selection, + gpointer data); static void gtk_entry_completion_insert_action (GtkEntryCompletion *completion, gint index, @@ -241,6 +243,10 @@ gtk_entry_completion_init (GtkEntryCompletion *completion) sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view)); gtk_tree_selection_set_mode (sel, GTK_SELECTION_SINGLE); gtk_tree_selection_unselect_all (sel); + g_signal_connect (sel, "changed", + G_CALLBACK (gtk_entry_completion_selection_changed), + completion); + priv->first_sel_changed = TRUE; priv->column = gtk_tree_view_column_new (); gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree_view), priv->column); @@ -663,6 +669,19 @@ gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column, NULL); } +static void +gtk_entry_completion_selection_changed (GtkTreeSelection *selection, + gpointer data) +{ + GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (data); + + if (completion->priv->first_sel_changed) + { + completion->priv->first_sel_changed = FALSE; + gtk_tree_selection_unselect_all (selection); + } +} + /* public API */ /** @@ -1017,11 +1036,12 @@ _gtk_entry_completion_popup (GtkEntryCompletion *completion) gint x, y, x_border, y_border; gint items; gint height; - GtkTreePath *path; if (GTK_WIDGET_MAPPED (completion->priv->popup_window)) return; + completion->priv->first_sel_changed = TRUE; + gtk_widget_show_all (completion->priv->vbox); gdk_window_get_origin (completion->priv->entry->window, &x, &y); @@ -1041,12 +1061,8 @@ _gtk_entry_completion_popup (GtkEntryCompletion *completion) if (items <= 0) gtk_widget_hide (completion->priv->scrolled_window); - /* default on the first match */ - path = gtk_tree_path_new_from_indices (0, -1); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (completion->priv->tree_view), path, - NULL, FALSE); - completion->priv->current_selected = 0; - gtk_tree_path_free (path); + /* default on no match */ + completion->priv->current_selected = -1; items = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL); diff --git a/gtk/gtkentryprivate.h b/gtk/gtkentryprivate.h index 741ec38038..657595e5a8 100644 --- a/gtk/gtkentryprivate.h +++ b/gtk/gtkentryprivate.h @@ -35,6 +35,7 @@ struct _GtkEntryCompletionPrivate GtkTreeViewColumn *column; GtkTreeModelFilter *filter_model; GtkListStore *actions; + gboolean first_sel_changed; GtkEntryCompletionMatchFunc match_func; gpointer match_data; -- 2.30.2